import QtQuick 1.0



Rectangle {
    id: rectangle1

//    property string day_of_week: "Mon"
//    property string condition: "cloudy"
//    property int low: 80 (in Fahrenheit)
//    property int high: 100 (in Fahrenheit)

    property alias day : dayText.text

    color: "white"
    width: 160
    height: 160
    radius: 10
    border.color: "white"
    border.width: 2




    Text {
        id: dayText
        text: day_of_week
        font.family: "Nokia Large Multiscript"
        anchors.bottom: image1.top
        anchors.bottomMargin: -8
        anchors.horizontalCenter: image1.horizontalCenter
        color: "#b56a20"
        font.pixelSize: 25
        z: 2
    }

    Text {
        id : clothing;

        property string picname;

        function toCelsius(fTemp) {
            var cTemp = (fTemp-32)*(5/9);
            var cTempStr = cTemp.toFixed(0);
            return cTempStr;
        }

        function isRaining(condStr) {
            var rain = (condStr.indexOf("Rain") != -1);
            return rain;
        }

        function suitableClothing(highTemp, isRaining) {
            var path = "";
            var file = "";
            var raincoat = (isRaining && highTemp >= 0) ? "_Rain" : "";

            if (highTemp > 26) {
                file = "Vitru_30" + raincoat + ".png";
            } else if (highTemp > 20) {
                file = "Vitru_20_30" + raincoat + ".png";
            } else if (highTemp > 0) {
                file = "Vitru_0_20" + raincoat + ".png";
            } else if (highTemp <= 0){
                file = "Vitru_0.png";
            }
            var filespec = path + file;
            picname = filespec;
            console.log(picname);
            return false;
        }

        function selectTemp() {
            if (high == 'undefined') {
                return temp_c;
            }
            return high;
        }

        anchors.verticalCenter: parent.verticalCenter
        anchors.left: parent.left
        anchors.margins: 10
        font.pixelSize: 15
        //text: toCelsius(high) + " C, " + condition + (suitableClothing(toCelsius(high), isRaining(condition)) ? "" : "");
        text: (suitableClothing(toCelsius(high), isRaining(condition)) ? "" : "")
        z: 2
    }

    Image {
        id: image1
        x: 0
        y: 0
        z: 1
        width: parent.width;
        height: parent.height;
        anchors.fill: parent
        anchors.margins: 0
        fillMode: Image.PreserveAspectFit
        source: clothing.picname;
    }

    MouseArea {
        width: parent.width
        height: parent.width
        anchors.fill: parent
        onClicked: {
            //parent.border.color = "red";
            //dayText.color = "black";
            if ( dayText.color == "#b56a20" ) { dayText.color = "black" }
            else { dayText.color = "#b56a20" };
            bigImage.source = clothing.picname;


        }

    }
}

